<extend name='Index/index' />

<block name="main">
                <div class="bg-light lter b-b wrapper-md">
                    <h1 class="m-n font-thin h3">视频管理</h1>
                    <button style="margin-top: 20px;" class="btn btn-success" data-toggle="modal" data-target="#myModal_add">添加作者</button>
                </div>
                <div class="wrapper-md">
                    <div class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-striped b-t b-light">
                                <thead>
                                    <tr>
                                        <th>作者ID</th>
                                        <th>名字</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <volist name='data' id='v'>
                                    <tr>
                                        <td><{$v.a_id}></td>
                                        <td><{$v.a_name}></td>
                                        <td>
                                            <if condition="$v.a_status eq 0"><a class="a_status">下线</a>
                                            <else /><a class="a_status">上线</a>
                                            </if>
                                        </td>
                                        <td>
                                        <a   class='btn btn-info' data-toggle="modal" data-target="#myModal" > 编辑</a> 
                                         <a  id="<{$v.v_id}>" class='btn btn-danger'>删除</a>
                                        </td>
                                    </tr>
                                    </volist>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <!-- 添加视频的模态框 -->
        <div class="modal fade" id="myModal_add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" id="add_close" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">添加作者</h4>
                </div>
                <div class="modal-body">
                    
                    <form class="form-horizontal" role="form" onsubmit="return false">
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">作者id</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="aid" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">作者名</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="addaname" value="">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button id="close" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button id="add" type="button" class="btn btn-primary">confirm</button>
                </div>
            </div>
        </div>
    </div>
<!-- 编辑视频的模态框 -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" id="guanbi" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">编辑</h4>
                </div>
                <div class="modal-body">
                    
                    <form class="form-horizontal" role="form" onsubmit="return false">
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-2 control-label">ID</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" id="id" readonly="" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-2 control-label">作者名</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" id="name" value="">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button id="close" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button id="save" type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>


<script type="text/javascript">
        $("a:contains('编辑')").click(function(){
            var id = $(this).parents('tr').children('td').eq(0).html();
            var name = $(this).parents('tr').children('td').eq(1).html();
            $('#id').val(id);
            $('#name').val(name);
            $('#save').click(function(){
                var id = $('#id').val();
                var name = $('#name').val();
                 $.ajax({
                url:"<{:U('edit')}>",
                type:"POST",
                data:{'a_id':id,'a_name':name},
                dataType:'json', 
                success: function(data){
                    if(data==1){
                        alert('编辑成功');
                        $('#guanbi').click();
                        window.location.reload();
                    }
                    if(data == 0){
                        alert('未做修改');
                        return false
                    }
                }
                })
            })
        })
            $('.a_status').click(function (){
                var str = $(this).html();
                var up = 0;
                var id = $(this).parents('tr').children('td').eq(0).html();
                if(str == '上线'){
                    $(this).html('下线');
                    up = 0;
                }else{
                    $(this).html('上线');
                    up = 1;
                }
                $.ajax({
                    url:"<{:U('e')}>",
                    type:"POST",
                    data:{'id':id,'up':up},
                    dataType:'json', 
                    
                });
            })
            $("a:contains('删除')").click(function(){
                var id = $(this).parents('tr').children('td').eq(0).html();
                $(this).parents('tr').remove();
                $.ajax({
                url:"<{:U('d')}>",
                type:"POST",
                data:{'a_id':id},
                dataType:'json', 
                success: function(data){
                    if(data == 1){
                        alert('删除成功');
                    }else{
                        alert('删除失败');
                    }
                    }
                })
            })
            $('#add').click(function(){
                var id = $('#aid').val();
                var a_name = $('#addaname').val();
                if(id == ''){
                    alert('作者ID不能为空');
                    return false;
                }
                if(a_name == ""){
                    alert('视频作者不能为空');
                    return false;
                }   
                $.ajax({
                url:"<{:U('add')}>",
                type:"POST",
                data:{'a_id':id,'a_name':a_name},
                dataType:'json', 
                success: function(data){
                    if(data > 0){
                        alert('添加成功');
                         window.location.reload();
                    }else{
                        alert('添加失败');
                        return false;
                    }
                    }
                })
            })
</script>
</block>
